#include "hot.hpp"
#include "server.hpp"
void DataTest()    
{
  cloud::DataManager data;
  std::vector<cloud::FileInfo>array;
  data.SelectAll(&array);
  for(auto &e : array)
  {

     std::cout<<e.filename<<std::endl;    
     std::cout<<e.url_path<<std::endl;    
     std::cout<<e.real_path<<std::endl;    
     std::cout<<e.file_size<<std::endl;    
     std::cout<<e.back_time<<std::endl;    
     std::cout<<e.pack_flag<<std::endl;    
     std::cout<<e.pack_path<<std::endl;    
  }
  /*
     cloud::DataManager data;    
     data.Insert("./backup_dir/hello.txt");    
     data.UpdateStatus("./backup_dir/hello.txt",true);    
     std::vector<cloud::FileInfo> array;    



     data.SelectAll(&array);    
     for (auto&e :array )    
     {    
     std::cout<<e.filename<<std::endl;    
     std::cout<<e.url_path<<std::endl;    
     std::cout<<e.real_path<<std::endl;    
     std::cout<<e.file_size<<std::endl;    
     std::cout<<e.back_time<<std::endl;    
     std::cout<<e.pack_flag<<std::endl;    
     std::cout<<e.pack_path<<std::endl;    
     }    

     std::cout<<"------------------"<<std::endl;    




     data.UpdateStatus("./backup_dir/hello.txt",false);    
     cloud::FileInfo e;    
     data.SelectOne("/download/hello.txt",&e);    
     std::cout<<e.filename<<std::endl;    
     std::cout<<e.url_path<<std::endl;    
     std::cout<<e.real_path<<std::endl;    
     std::cout<<e.file_size<<std::endl;    
     std::cout<<e.back_time<<std::endl;    
     std::cout<<e.pack_flag<<std::endl;    
     std::cout<<e.pack_path<<std::endl;    



     std::cout<<"------delete------"<<std::endl;    

     data.DeleteOne("/download/hello.txt");    
     array.clear();    

     data.SelectAll(&array);    
     for(auto &e :array)    
     {    
     std::cout<<e.filename<<std::endl;    
     std::cout<<e.url_path<<std::endl;    
     std::cout<<e.real_path<<std::endl;    
     std::cout<<e.file_size<<std::endl;    
     std::cout<<e.back_time<<std::endl;    
     std::cout<<e.pack_flag<<std::endl;    
     std::cout<<e.pack_path<<std::endl;    
     }    

*/ 
} 
void FileUtilTest()
{
  //cloud::FileUtil("./testdir/adir").CreateDirectory();
  //测试创建目录


  //cloud::FileUtil("./testdir/a.txt").Write("YXY\n");
  //测试写入数据


  //std::string body;
  //cloud::FileUtil("./testdir/a.txt").Read(&body);
  //std::cout<<body<<std::endl;
  //测试读取数据



  //std::cout << cloud::FileUtil("./testdir/a.txt").Size()<<std::endl;
  //std::cout << cloud::FileUtil("./testdir/a.txt").MTime()<<std::endl;
  //std::cout << cloud::FileUtil("./testdir/a.txt").ATime()<<std::endl;
  //测试文件大小，文件最后一次修改时间，最后一次访问时间


  //std::vector<std::string> array;
  //cloud::FileUtil("./testdir").ScanDirectory(&array);
  //for(auto &a :array){
  //  std::cout << a << std::endl;
  //}
}

void JsonTest()
{
  
     Json::Value val;
     val["性别"]="虞心怡";
     val["性别"]="男";
     val["年龄"]=18;
     val["成绩"].append(77);
     val["成绩"].append(78);
     val["成绩"].append(79);

     std::string body;
     cloud::JsonUtil::Serialize(val,&body);
     std::cout<<body<<std::endl;

     Json::Value root;
     cloud::JsonUtil::UnSerialize(body,&root);
     std::cout<<root["姓名"].asString() <<std::endl;
     std::cout<<root["性别"].asString() <<std::endl;
     std::cout<<root["年龄"].asInt() <<std::endl;
     std::cout<<root["成绩"][0].asFloat() <<std::endl;
     std::cout<<root["成绩"][1].asFloat() <<std::endl;
     std::cout<<root["成绩"][2].asFloat() <<std::endl;
    
}




void CompressTest()
{
  cloud::FileUtil("./test1.txt").Compress("test1.zip");
  cloud::FileUtil("test1.zip").Uncompress("test2.txt");
}





cloud::DataManager *_data;
void HotTest()
{
  cloud::HotManager cloud;
  cloud.RunModule();
}




void ServerTest()
{
  cloud::Server srv;
  srv.RunModule();
}




int main()
{
  _data = new cloud::DataManager();
  //FileUtilTest();
  // JsonTest();
  //CompressTest();
  //DataTest();
  //HotTest();
  ServerTest();
  return 0;

}















